package formatter;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Responsible for writing objects into its appropriate TOKI format
 * @author dolphinigle
 */
public class PelatnasFormatter extends CodeforcesFormatter {

  private String prefix_;
  private String suffix_;
  
  /**
   * Constructs a new Pelatnas formatter
   * The file name will be:
   * prefix + init_filename_count_ + suffix
   * prefix + (init_filename_count_+1) + suffix
   * etc.
   * 
   * example: prefix "test", suffix ".in":
   * becomes test1.in, test2.in, ...
   */
  public PelatnasFormatter(String base_path, int init_filename_count_,
                           String prefix, String suffix) {
    super(base_path, init_filename_count_);
    prefix_ = prefix;
    suffix_ = suffix;
  }

  @Override
  public void open() {
    assert !file_opened_;
    file_opened_ = true;
    String filename = base_path_ + prefix_ +
        String.valueOf(next_filename_count_) + suffix_;
    ++next_filename_count_;
    try {
      this.writer_ = new BufferedWriter(new FileWriter(filename));
    } catch (IOException ios) {
      throw new Error(ios.toString());
    }
  }
}
